//
//  @ Project : Galaxy Star Trading System
//  @ File Name : XgjTradeApi.h
//  @ Date : 2014/9/5
//  @ Author :
//
//


#if !defined(_CXGJTRADEAPI_H_H)
#define _CXGJTRADEAPI_H_H

#ifdef BUILD_XGJ

#include "../ctp/api/ThostFtdcUserApiDataType.h"
#include "../ctp/api/ThostFtdcUserApiStruct.h"

#include "api/CmsTraderApi.h"

namespace GSTrader
{
	namespace TradeService
	{
		class CXgjTradeSpiImpl;
		class  CXgjTradeApiImpl : public CTradeApi
		{
		public:
			CXgjTradeApiImpl();
			virtual ~CXgjTradeApiImpl();

			virtual int Init(TradeApiConnParam& param);
			virtual void Destory();

			virtual int ReqUserLogin();
			virtual int ReqQryOrder();
			virtual int ReqQryTrade();
			virtual int ReqUserLogOut();
			virtual int ReqQryExchange(string strExchangeID);
			virtual int ReqQryDepthMarketData(string strInstrumentID);
			virtual int ReqQrySettlementInfo(string strTradingDay);
			virtual int ReqSettlementInfoConfirm();
			virtual int ReqQrySettlementInfoConfirm();
			virtual int ReqQryInvestorPositionDetail(string strInstrumentID);
			virtual int ReqQryNotice();
			virtual int ReqQryInvestorPositionCombineDetail(string strInstrumentID);
			virtual int ReqQryInvestorPosition(string strInstrumentID);
			virtual int ReqQryTradingAccount();
			virtual int ReqQryInstrument(string strInstrumentID);
			virtual int ReqQryInstrumentMarginRate(string strInstrumentID, char chHedgeFlag);
			virtual int ReqQryInstrumentCommissionRate(string strInstrumentID);
			virtual int ReqQueryMaxOrderVolume();
			virtual int ReqQryBrokerTradingParams();
			virtual int ReqQryBrokerTradingAlgos(string strExchangeID, string strInstrumentID);
			virtual int ReqQryInvestor();
			virtual int ReqQryTradingCode();
			virtual int ProcessRequestMsg(CMsg* pMsg);
		public:
			virtual int ReqOrderInsert(COrder* pOrder);
			virtual int ReqOrderAction(COrder& srcOrder);

		public: 
			virtual int ReqParkedOrderInsert(COrder* pOrder){return 0;}
			virtual int ReqParkedOrderAction(){	return 0;}
			virtual int ReqQryComplianceParam(string strExchangeId)	{return 0;}

		private:
			CXgjTradeSpiImpl* m_pSpiImpl;
			CCmsTraderApi*	 m_pTradeApi;

			CThostFtdcBrokerTradingParamsField m_TradingParams;

		private:
			COrder  m_last;
			mutex		m_Mutex;
			friend class CXgjTradeSpiImpl;
			friend class CXgjDataBaseHelper;
		};

	}
}

#endif

#endif //_CXGJTRADEAPI_H_H
